package com.yonyou.pmclouds.externalservice.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yonyou.pmclouds.ApplicationConsts;
import com.yonyou.pmclouds.basecom.entity.PageObject;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.externalservice.entity.FailedExternalRecordVO;
import com.yonyou.pmclouds.externalservice.rmiitf.FailedExternalRecordMaintain;
import com.yonyou.pmclouds.externalservice.rmiitf.FailedExternalRecordQuery;
import org.springframework.web.bind.annotation.*;


import static com.yonyou.pmclouds.basecom.PMControllerConst.DEFAULT_PAGE_PAGE_START;
import static com.yonyou.pmclouds.basecom.PMControllerConst.DEFAULT_PAGE_SIZE;

@RestController
@RequestMapping("/mobile/failedRecord")
public class FailedExternalRecordController {

    @Reference(version = ApplicationConsts.APPLICATION_VERSION)
    private FailedExternalRecordMaintain recordMaintain;

    @Reference(version = ApplicationConsts.APPLICATION_VERSION)
    private FailedExternalRecordQuery recordQuery;

    @RequestMapping("/list")
    @ResponseBody
    public PageObject<FailedExternalRecordVO> getFailedRecordByUser(@RequestParam("tenantId") String tenantId,
                                                        @RequestParam("userId") String userId,
                                                        @RequestParam(name = "pageStart", required = false,
                                                          defaultValue = DEFAULT_PAGE_PAGE_START) String pageStart,
                                                        @RequestParam(name = "pageSize", required = false,
                                                          defaultValue = DEFAULT_PAGE_SIZE) String pageSize) throws BusinessException{
        return recordQuery.getFailedRecordByUser(tenantId, userId, Integer.valueOf(pageStart), Integer.valueOf(pageSize));
    }

    @RequestMapping("/delete")
    @ResponseBody
    public FailedExternalRecordVO deleteNotice(@RequestParam("pkBill") String pkBill, @RequestParam("billType") String billType) throws BusinessException{
        return recordMaintain.deleteRecordWithBill(pkBill, billType);
    }

    @RequestMapping("/checkFailedRecord")
    @ResponseBody
    public int checkFailedRecord(@RequestParam("tenantId") String tenantId, @RequestParam("userId") String userId) throws BusinessException{
        return recordQuery.checkFailedRecord(userId, tenantId);
    }

}
